Ext.extend(SHED.module, {
    init: function() {
        var userWin = new SHED.Window({
            id: 'userWin',
            title: '用户资料',
            height: 200,
            items: new SHED.form.DWRForm({
                afterSubmit: function() {
                    grid.reload();
                },
                labelWidth: 85,
                dwr: {
                    load: smDwr.getUserByUserId,
                    save: smDwr.createUser,
                    update: smDwr.updateUser
                },
                items: [{
                    fieldLabel: '用户ID',
                    name: 'userID',
                    xtype: 'hidden'
                }, {
                    fieldLabel: '用户密码',
                    name: 'userPwd',
                    value: '000000',
                    xtype: 'hidden'
                }, {
                    fieldLabel: '用户名称',
                    name: 'userName',
                    allowBlank: false,
                    validator: function(v) {
                        return (/[\W]/).test(v) ? "用户名只能由英文字母、数字和下划线组成！" : true;
                    }
                }, {
                    store: [[1, '有效'], [0, '无效']],
                    triggerAction: 'all',
                    mode: 'local',
                    editable: false,
                    fieldLabel: '状　　态',
                    hiddenName: 'userState',
                    value: 1,
                    xtype: 'combo'
                }, {
                    fieldLabel: '用户说明',
                    name: 'userDesc',
                    xtype: 'textarea'
                }]
            })
        });
        
        var addBtn = new Ext.Toolbar.Button({
            text: '添加用户',
            iconCls: 'btn_insert',
            handler: function(o, e) {
                userWin.show();
            }
        });
        
        var editBtn = new Ext.Toolbar.Button({
            text: '修改用户',
            iconCls: 'btn_modify',
            handler: function(o, e) {
                var record = grid.getSelectedRow();
                if (record) {
                    userWin.load(record.userID);
                } else {
                    SHED.msg('请选择要修改的用户！');
                }
            }
        });
        
        var grid = new SHED.grid.PageGrid({
            id: 'userGrid',
            initload: true,
            firstColumn: 'radio',
            tbar: ['-', addBtn, editBtn],
            filter: {},
            listeners: {
                'rowdblclick': editBtn.handler
            },
            dwr: {
                call: smDwr.pageUser
            },
            metas: [{
                id: 'userID',
                field: 'userID',
                type: 'int',
                hidden: true
            }, {
                field: 'userName',
                desc: '用户名'
            }, {
                field: 'userDesc',
                desc: '用户说明'
            }, {
                field: 'userState',
                desc: '状　　态',
                renderer: function(val) {
                    return val == 1 ? '有效' : '无效';
                }
            }]
        });
        
        this.main.associatedComp = [userWin];
        this.main.add(grid);
        this.main.doLayout();
    }
});
